﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WiMo.Games.Drawables;
using WiMo.Games.GameEngine.WP7S;

namespace WiMo.Games.GameEngine.WP7S.Drawables
{
    public class SpriteText : SpriteTextBase
    {
        TextBlock _textBlock;

        public SpriteText()
        {
            
            //var tg = new TransformGroup();


            //textBlock.Margin = new Thickness((double)text.Position.X, (double)text.Position.Y, 0, 0);
        }

        public override void Render(IDisplay display)
        {
            _textBlock = new TextBlock();
            _textBlock.TextAlignment = TextAlignment.Center;
            _textBlock.HorizontalAlignment = HorizontalAlignment.Center;
            _textBlock.Text = Text;
            _textBlock.Foreground = new System.Windows.Media.SolidColorBrush(ForeColor.GetMediaColor());                        
            
            TransformGroup tg = new TransformGroup();
            var translate = new TranslateTransform();
            var rotate = new RotateTransform();
            var scale = new ScaleTransform();
            scale.ScaleX = Scale.X;
            scale.ScaleY = Scale.Y;

            //translate.X = Position.X;
            //translate.Y = Position.Y;

            tg.Children.Add(translate);
            tg.Children.Add(rotate);
            tg.Children.Add(scale);

            _textBlock.RenderTransform = tg;

            if(Origin == Origin.Center)
            {
                _textBlock.SetValue(Canvas.TopProperty, (double)Position.Y - _textBlock.ActualHeight / 2);
                _textBlock.SetValue(Canvas.LeftProperty, (double)Position.X - _textBlock.ActualWidth / 2);
            }
            else
            {
                _textBlock.SetValue(Canvas.TopProperty, (double)Position.Y - _textBlock.ActualHeight);
                _textBlock.SetValue(Canvas.LeftProperty, (double)Position.X - _textBlock.ActualWidth);
            }


            DrawInformation = _textBlock;

            display.Render(this);
        }
    }
}
